<?php

namespace app\common\traits;

use think\Exception;

trait ResultTrait
{
    /**
     * 统一返回内容
     * @param $response
     * @return array
     */
    protected function result($response)
    {
        $ret = [
            "result" => false,
            "msg" => '',
            "data" => [],
        ];

        if (is_array($response)) {
            $ret['result'] = ($response["status"] === 200);
            $ret['msg'] = $response["msg"];
            $ret['data'] = $response["data"] ?? [];
        }
        if ($response instanceof Exception) {
            $ret['msg'] = $response->getMessage();
        }
        return $ret;

    }
}